// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// import 'babel-polyfill'
// import Vue from 'vue'
import App from './App'
// import axios from 'axios'
// import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import router from './router'
import store from './vuex/store'
// import VueRouter from 'vue-router'
import Lockr from 'lockr'
import _g from './assets/js/global'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import './assets/css/element-ui.css'

import './assets/js/common'
import './assets/css/list.css'
import './assets/css/search.css'
import './assets/css/info.css'
import './assets/css/common.css'

import apiMethods from './assets/js/http'

Vue.prototype.apiGet = apiMethods.methods.apiGet;
Vue.prototype.apiPost = apiMethods.methods.apiPost;

import QRCode from 'qrcode'

Vue.use(QRCode);
window.QRCode = QRCode;

// 引入echarts
// import echarts from 'echarts'

Vue.prototype.$echarts = echarts;

// window.router = new VueRouter({
//     routes
// });

router.beforeEach((to, from, next) => {
    NProgress.start();
    if (to.path !== '/login') {
        axios.get(PATH + 'System/look').then(res => {
            console.log(res);
            if (res.data.error === 8) {
                router.replace('/login')
            } else {
                window.USERNAME = res.data.username;
                next()
            }
            next()
        })
        
    } else {
        next()
    }
});
router.afterEach(transition => {
    NProgress.done();
});

Vue.config.productionTip = true;
// Vue.use(ElementUI);
// Vue.use(VueRouter);

window.router = router;
window._g = _g;
window.axios = axios;
window.store = store;
window.Lockr = Lockr;

const bus = new Vue();
window.bus = bus;

// window.PATH = '/index.php/index/';
window.SITE = 'http://oa.namtc.com.cn/#/';
window.SITE1 = 'http://oa.namtc.com.cn/';
window.PATH = '/api/';


new Vue({
    el: '#app',
    router,
    store,
    template: '<App/>',
    components: {App}
});


